package Ioperations;

import book.Bookshelf;

import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28318
 * Date: 2025-10-28
 * Time: 17:33
 */
public class ReturnIoperation implements Ioperations{
    @Override
    public void work(Bookshelf book) {
        System.out.println("***>归还图书...<***");
        Scanner inPut = new Scanner(System.in);
        System.out.println("输入您要归还的图书名:");
        String name = inPut.nextLine();
        int address = -1;
        for (int i = 0; i < book.getBookUsed(); i++) {
            if (book.bookshelf[i].getName().equals(name)){
                address = i;
                break;
            }
        }
        if (address == -1){
            System.out.println("未找到您要归还的图书...");
            return;
        }
        if (book.bookshelf[address].isBorrowed() != false){
            book.bookshelf[address].setBorrowed(false);
            System.out.println("归还成功...");
        }else {
            System.out.println("该图书已被他人归还...");
        }
    }
}
